package com.pz.gulimall.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@Configuration
public class ScheduleConfig implements AsyncConfigurer, SchedulingConfigurer {
    @Value("${gulimall.thread.core-size}")
    private int threadPoolCoreSize;

    /**
     *  异步定时任务注册
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(threadPoolCoreSize);
        scheduler.setThreadNamePrefix("app-schedule-");
        scheduler.setAwaitTerminationMillis(600);

        taskRegistrar.setTaskScheduler(scheduler);
    }
}
